# -*- coding: utf-8 -*-
# @Time : 2021/9/14 16:40
# @Author : hello
# @Email : xxx@gmail.com
# @File : cusyecz.py
# @Project : crm
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from time import  sleep

class CusYeCz():

    def __init__(self,driver):
        self.driver=driver

    #客户界面功能属性
    tables = (By.CSS_SELECTOR, "#form1 > table")
    tbodys = (By.TAG_NAME, "tbody")
    trs = (By.TAG_NAME, "tr")
    tds = (By.TAG_NAME, "td")
    a = (By.TAG_NAME, "a")
    sylxr = (By.ID, 'contacts_name')

    def clue_table(self):
        """返回表格中的tr"""
        table = self.driver.find_element(*self.tables)
        tbody = table.find_element(*self.tbodys)
        trss = tbody.find_elements(*self.trs)
        return trss

    def cus_edit(self):
        """客户界面编辑"""
        for tr in self.clue_table():
            td = tr.find_elements(*self.tds)
            if td[-1]:
                sleep(3)
                td[-1].find_elements(*self.a)[-1].click()
                break

    def checkcust(self):
        """客户界面查看"""
        for tr in self.clue_table():
            td = tr.find_elements(*self.tds)
            if td[-1]:
                sleep(3)
                td[-1].find_elements(*self.a)[0].click()
                break

    def prompt(self):
        alert = Alert(self.driver)
        alert.accept()

